<?php

namespace Util;
class Rest
{
    /**
     * 解析payload
     * @param $post
     * @return mixed
     * @throws \Exception
     */
    public static function decodePayload($post)
    {
        if (isset($post['payload'])) {
            $decode_result = base64_decode($post['payload']);
            if ($decode_result) {
                @parse_str($decode_result, $array);
                if ($array) {
                    return $array;
                } else {
                    throw new \Exception('payload 格式错误', 0);
                }
            } else {
                throw new \Exception('payload 数据格式错误', 0);
            }
        } else {
            throw new \Exception('payload 数据未传', 0);
        }
    }
}